package cho05;

/**
 * Created by 春旺 on 2017/4/3.
 */
public class Coin53
{
    enum choose {head, tails}
    choose a = choose.head;
    choose b = choose.tails;

    private final int HEADS = 0; // tails is 1
    private int face; // current side showing
    //-----------------------------------------------------------------
// Sets up this coin by flipping it initially.
//-----------------------------------------------------------------
    public Coin53 ()
    {

        flip();
    }
    //-----------------------------------------------------------------
// Flips this coin by randomly choosing a face value.
//-----------------------------------------------------------------
    public void flip ()
    {
        face = (int) (Math.random() * 2);
    }
    //-----------------------------------------------------------------
// Returns true if the current face of this coin is heads.
//-----------------------------------------------------------------
    public boolean isHeads ()
    {
        return (face == HEADS);
    }
    //-----------------------------------------------------------------
// Returns the current face of this coin as a string.
//-----------------------------------------------------------------
    public String toString()
    {
        choose c =(face == HEADS) ? a : b;
        return c.toString();
    }
}
